package com.mycase.im.boot.controller;

import com.mycase.im.boot.entity.database.ImMessage;
import com.mycase.im.boot.service.MessageService;
import com.mycase.im.boot.service.UserService;
import com.mycase.im.boot.entity.communication.ResponseMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

import java.util.List;

import static com.mycase.im.boot.entity.communication.ResponseMessage.*;

/**
 * @Author ZhuHJay
 * @Date 2021/8/21 10:13
 */
@RestController
@RequestMapping("/api/message")
public class MessageController {

    @Autowired
    private UserService userService;
    @Autowired
    private MessageService messageService;

    @Deprecated
    @GetMapping("/chatRecord")
    public ResponseMessage getChatRecord(
            @NotBlank(message = "请求失败, 请重试") String id,
            @NotBlank(message = "请求失败, 请重试") String fId){

        // 安全判断: 是否存在
        if( !userService.isExist(id) || !userService.isExist(fId) ){
            return error("不存在用户");
        }

        // 获取聊天记录
        List<ImMessage> messageList = messageService.getMessageRecord(id, fId);

        return success().appendData("chatRecord", messageList);
    }

}
